package com.info33.platform.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.info33.platform.system.dao.SysMenuDao;
import com.info33.platform.system.dao.SysTenantDao;
import com.info33.platform.system.entity.SysMenu;
import com.info33.platform.system.entity.SysTenant;
import com.info33.platform.system.service.SysMenuService;
import com.info33.platform.system.vo.SysMenuVO;

/**
 * @author admin
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuDao, SysMenu> implements SysMenuService {

    @Autowired
    SysMenuDao sysMenuDao;
    @Autowired
    SysTenantDao sysTenantDao;

	@Override
	public List<SysMenuVO> getMenuTree(Long tenantId, Integer operateType) {
		if(!StringUtils.isEmpty(tenantId)) {
			SysTenant sysTenant = sysTenantDao.selectById(tenantId);
			return menuTree(sysMenuDao.selectMenuList(sysTenant, operateType), 0L);
		}
		return null;
	}
	public List<SysMenuVO> menuTree(List<SysMenuVO> sysMenuVOList, Long pid) {
        List<SysMenuVO> collect = sysMenuVOList.stream().filter(l -> l.getPid().equals(pid)).collect(Collectors.toList());
        collect.forEach(l -> l.setChildren(menuTree(sysMenuVOList, l.getId())));
        return collect;
    }

}